c29f106d3eee2312bf8f7e8d85fff78c9e75e504,Core/src/org/sleuthkit/autopsy/report/ReportGenerator.java,ReportGenerator,writeKeywordHits,#List#String#HashSet#,870

Before Change


            }

            // Make keyword data type and give them set index
            for (TableReportModule module : tableModules) {
                module.startDataType(ARTIFACT_TYPE.TSK_KEYWORD_HIT.getDisplayName(), comment);
                module.addSetIndex(lists);
                tableProgress.get(module).updateStatusLabel(
                        NbBundle.getMessage(this.getClass(), "ReportGenerator.progress.processing",
                                ARTIFACT_TYPE.TSK_KEYWORD_HIT.getDisplayName()));
            }
        } catch (TskCoreException | SQLException ex) {
            errorList.add(NbBundle.getMessage(this.getClass(), "ReportGenerator.errList.failedQueryKWLists"));
            logger.log(Level.SEVERE, "Failed to query keyword lists: ", ex); //NON-NLS
            return;
        }

        if (currentCase.getCaseType() == Case.CaseType.MULTI_USER_CASE) {
            orderByClause = "ORDER BY convert_to(att3.value_text, 'SQL_ASCII') ASC NULLS FIRST, " //NON-NLS
                    + "convert_to(att1.value_text, 'SQL_ASCII') ASC NULLS FIRST, " //NON-NLS
                    + "convert_to(f.parent_path, 'SQL_ASCII') ASC NULLS FIRST, " //NON-NLS
                    + "convert_to(f.name, 'SQL_ASCII') ASC NULLS FIRST, " //NON-NLS
                    + "convert_to(att2.value_text, 'SQL_ASCII') ASC NULLS FIRST"; //NON-NLS
        } else {
            orderByClause = "ORDER BY list ASC, keyword ASC, parent_path ASC, name ASC, preview ASC"; //NON-NLS
        }
        // Query for keywords, grouped by list
        String keywordsQuery
                = "SELECT art.artifact_id, art.obj_id, att1.value_text AS keyword, att2.value_text AS preview, att3.value_text AS list, f.name AS name, f.parent_path AS parent_path "
                + //NON-NLS
                "FROM blackboard_artifacts AS art, blackboard_attributes AS att1, blackboard_attributes AS att2, blackboard_attributes AS att3, tsk_files AS f "
                + //NON-NLS
                "WHERE (att1.artifact_id = art.artifact_id) "
                + //NON-NLS
                "AND (att2.artifact_id = art.artifact_id) "
                + //NON-NLS
                "AND (att3.artifact_id = art.artifact_id) "
                + //NON-NLS
                "AND (f.obj_id = art.obj_id) "
                + //NON-NLS
                "AND (att1.attribute_type_id = " + ATTRIBUTE_TYPE.TSK_KEYWORD.getTypeID() + ") "
                + //NON-NLS
                "AND (att2.attribute_type_id = " + ATTRIBUTE_TYPE.TSK_KEYWORD_PREVIEW.getTypeID() + ") "
                + //NON-NLS
                "AND (att3.attribute_type_id = " + ATTRIBUTE_TYPE.TSK_SET_NAME.getTypeID() + ") "
                + //NON-NLS
                "AND (art.artifact_type_id = " + ARTIFACT_TYPE.TSK_KEYWORD_HIT.getTypeID() + ") "
                + //NON-NLS
                orderByClause; //NON-NLS

        try (CaseDbQuery dbQuery = skCase.executeQuery(keywordsQuery)) {
            ResultSet resultSet = dbQuery.getResultSet();

            String currentKeyword = "";
            String currentList = "";
            while (resultSet.next()) {
                // Check to see if all the TableReportModules have been canceled
                if (tableModules.isEmpty()) {
                    break;
                }
                Iterator<TableReportModule> iter = tableModules.iterator();
                while (iter.hasNext()) {
                    TableReportModule module = iter.next();
                    if (tableProgress.get(module).getStatus() == ReportStatus.CANCELED) {
                        iter.remove();
                    }
                }

                // Get any tags that associated with this artifact and apply the tag filter.
                HashSet<String> uniqueTagNames = getUniqueTagNames(resultSet.getLong("artifact_id")); //NON-NLS
                if (failsTagFilter(uniqueTagNames, tagNamesFilter)) {
                    continue;
                }
                String tagsList = makeCommaSeparatedList(uniqueTagNames);

                Long objId = resultSet.getLong("obj_id"); //NON-NLS
                String keyword = resultSet.getString("keyword"); //NON-NLS
                String preview = resultSet.getString("preview"); //NON-NLS
                String list = resultSet.getString("list"); //NON-NLS
                String uniquePath = "";

                try {
                    AbstractFile f = skCase.getAbstractFileById(objId);
                    if (f != null) {
                        uniquePath = skCase.getAbstractFileById(objId).getUniquePath();
                    }
                } catch (TskCoreException ex) {
                    errorList.add(
                            NbBundle.getMessage(this.getClass(), "ReportGenerator.errList.failedGetAbstractFileByID"));
                    logger.log(Level.WARNING, "Failed to get Abstract File by ID.", ex); //NON-NLS
                }

                // If the lists aren't the same, we've started a new list
                if ((!list.equals(currentList) && !list.isEmpty()) || (list.isEmpty() && !currentList.equals(
                        NbBundle.getMessage(this.getClass(), "ReportGenerator.writeKwHits.userSrchs")))) {
                    if (!currentList.isEmpty()) {
                        for (TableReportModule module : tableModules) {
                            module.endTable();
                            module.endSet();
                        }
                    }
                    currentList = list.isEmpty() ? NbBundle
                            .getMessage(this.getClass(), "ReportGenerator.writeKwHits.userSrchs") : list;
                    currentKeyword = ""; // reset the current keyword because it's a new list
                    for (TableReportModule module : tableModules) {
                        module.startSet(currentList);
                        tableProgress.get(module).updateStatusLabel(
                                NbBundle.getMessage(this.getClass(), "ReportGenerator.progress.processingList",
                                        ARTIFACT_TYPE.TSK_KEYWORD_HIT.getDisplayName(), currentList));
                    }
                }
                if (!keyword.equals(currentKeyword)) {
                    if (!currentKeyword.equals("")) {
                        for (TableReportModule module : tableModules) {
                            module.endTable();
                        }
                    }
                    currentKeyword = keyword;
                    for (TableReportModule module : tableModules) {
                        module.addSetElement(currentKeyword);
                        List<String> columnHeaderNames = new ArrayList<>();
                        columnHeaderNames.add(NbBundle.getMessage(this.getClass(), "ReportGenerator.artTableColHdr.preview"));
                        columnHeaderNames.add(NbBundle.getMessage(this.getClass(), "ReportGenerator.artTableColHdr.srcFile"));
                        columnHeaderNames.add(NbBundle.getMessage(this.getClass(), "ReportGenerator.artTableColHdr.tags"));
                        module.startTable(columnHeaderNames);
                    }
                }

                String previewreplace = EscapeUtil.escapeHtml(preview);
                for (TableReportModule module : tableModules) {
                    module.addRow(Arrays.asList(new String[]{previewreplace.replaceAll("<!", ""), uniquePath, tagsList}));
                }
            }

After Change


            // Make keyword data type and give them set index
            tableModule.startDataType(ARTIFACT_TYPE.TSK_KEYWORD_HIT.getDisplayName(), comment);
            tableModule.addSetIndex(lists);
            progressPanel.updateStatusLabel(
                    NbBundle.getMessage(this.getClass(), "ReportGenerator.progress.processing",
                            ARTIFACT_TYPE.TSK_KEYWORD_HIT.getDisplayName()));
        } catch (TskCoreException | SQLException ex) {
            errorList.add(NbBundle.getMessage(this.getClass(), "ReportGenerator.errList.failedQueryKWLists"));
            logger.log(Level.SEVERE, "Failed to query keyword lists: ", ex); //NON-NLS